package com.feige.controller;


import com.feige.result.AjaxResult;
import com.feige.service.RolePermissionService;
import com.feige.service.UserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author feige
 * @since 2020-07-20
 */
@Api(tags = "用户角色类")
@RestController
@RequestMapping("/user-role")
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;


    @PreAuthorize("@ss.hasPerm('user:user:add')")
    @ApiOperation(value = "给用户分配角色")
    @PostMapping("/Assign-role")
    public AjaxResult AssignPermissions(@ApiParam(name = "userId", value = "用户ID", required = true) Long userId,
                                        @ApiParam(name = "roleId", value = "角色ID数组", required = true) Long[] roleId){
        boolean assignRoles = userRoleService.AssignRoles(userId, roleId);
        if (assignRoles){
            return AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }
}

